#include "audio_output_helper.h"
#include <limits>
using namespace krryn::audio;

int_16* output_helper::convert_for_output(sample::ptr a_Sample){
	audio::int_16 *l_Dest = new audio::int_16[a_Sample->count()];

	audio::sample::value_type *l_Source = a_Sample->buffer();

	for(int i = 0; i < a_Sample->count(); i++){
		// clip the final range
		if(*l_Source > +1) *l_Source = +1;
		if(*l_Source < -1) *l_Source = -1;

		// convert the intermediate format to 16 bits for outputting
		l_Dest[i] = static_cast<audio::int_16>(
			*l_Source++ * (std::numeric_limits<audio::int_16>::max)()
		);
	}

	return l_Dest;
}